<template>
  <view class="wrapper">
    <view class="container">
      <VueEcharts :option="options" />
    </view>
  </view>
</template>

<script setup>
import * as echarts from 'echarts';
import { onMounted, ref } from 'vue';
import VueEcharts from 'vue-echarts';
// defineProps({
//   color: String
//   default: 'yellow'
// });
// 初始进度值
const props = defineProps({
  color: String,
});
// const color = ref('yellow');
const options = ref(null);
onMounted(() => {
  upData();
});

const colorsList = {
  yellow: [
    {
      offset: 0,
      color: '#FFE09E',
    },
    {
      offset: 1,
      color: '#FFB412',
    },
  ],
  blue: [
    {
      offset: 0,
      color: '#A5E0F2',
    },
    {
      offset: 1,
      color: '#29B9E6',
    },
  ],
  green: [
    {
      offset: 0,
      color: '#9BEBB3',
    },
    {
      offset: 1,
      color: '#21D155',
    },
  ],
};

const upData = () => {
  options.value = {
    title: {
      text: '男生公寓',
      subtext: '93%',
      left: 'center',
      top: '38%',
      textStyle: {
        color: '#758291',
        fontSize: 12,
      },
      subtextStyle: {
        color: '#1a2b5c',
        fontSize: 20,
      },
    },
    tooltip: {
      trigger: 'item',
    },
    legend: {
      top: '5%',
      left: 'center',
      show: false,
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['60%', '75%'],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: 'center',
        },
        emphasis: {
          label: {
            show: false,
            fontSize: 40,
            fontWeight: 'bold',
          },
        },
        labelLine: {
          show: false,
        },
        data: [

          { value: 1735, name: 'Direct', itemStyle: {
            normal: {
              barBorderRadius: [5, 5, 0, 0],
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, colorsList[props.color]),
            },
          } },
          { value: 1048, name: 'Search Engine', itemStyle: { normal: { color: '#f5f9fc' } } },
        ],
      },
    ],
  };
};
</script>

<style lang="scss" scoped>
	.wrapper {
		width: 100%;
		box-sizing: border-box;
		height: 280rpx;
	}
	.container{
		width: 100%;
		height: 100%;
	}
</style>
